package top.gardel.test;

public class MainActivity extends android.app.Activity
{
	android.widget.TextView tv;
    @Override
    protected void onCreate(android.os.Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
		tv = (android.widget.TextView) findViewById(R.id.mainTextView1);
    }

	public void GetBT(android.view.View v) {
		top.gardel.httputils.HttpUtils.Get(this, "http://www.example.com/", null, new top.gardel.httputils.EventHander() {
				@Override
				public void onSuccess(String result) {
					tv.setText(result);
				}

				@Override
				public void onSuccess(java.io.File file) {
					// TODO: Implement this method
				}

				@Override
				public void onFailed(String msg) {
					android.widget.Toast.makeText(getApplicationContext(), msg, android.widget.Toast.LENGTH_SHORT).show();
				}
			});
	}
	
	public void GetQBT(android.view.View v) {
		java.util.TreeMap<String, String> params = new java.util.TreeMap<>();
		params.put("key", "value");
		top.gardel.httputils.HttpUtils.Get(this, "http://www.example.com/", params, new top.gardel.httputils.EventHander() {
				@Override
				public void onSuccess(String result) {
					tv.setText(result);
				}

				@Override
				public void onSuccess(java.io.File file) {
					// TODO: Implement this method
				}

				@Override
				public void onFailed(String msg) {
					android.widget.Toast.makeText(getApplicationContext(), msg, android.widget.Toast.LENGTH_SHORT).show();
				}
			});
	}
	
	public void PostBT(android.view.View v) {
		java.util.TreeMap<String, String> params = new java.util.TreeMap<>();
		params.put("key", "value");
		top.gardel.httputils.HttpUtils.Post(this, "http://www.example.com/", params, false, new top.gardel.httputils.EventHander() {
				@Override
				public void onSuccess(String result) {
					tv.setText(result);
				}

				@Override
				public void onSuccess(java.io.File file) {
					// TODO: Implement this method
				}

				@Override
				public void onFailed(String msg) {
					android.widget.Toast.makeText(getApplicationContext(), msg, android.widget.Toast.LENGTH_SHORT).show();
				}
			});
	}
	
	public void DownloadBT(android.view.View v) {
		top.gardel.httputils.HttpUtils.Download(this, "http://www.example.com/", null, android.os.Environment.getExternalStorageDirectory().getPath() + "/example.html", new top.gardel.httputils.EventHander() {
				@Override
				public void onSuccess(String result) {
					// TODO: Implement this method
				}

				@Override
				public void onSuccess(java.io.File file) {
					tv.setText("File save to \"" + file.getPath() + "\"");
				}

				@Override
				public void onFailed(String msg) {
					android.widget.Toast.makeText(getApplicationContext(), msg, android.widget.Toast.LENGTH_SHORT).show();
				}
			});
	}
}
